//引入公共样式
require("../../assets/js/commonCss");
require('./mine.less')
    // 使用公共尾部
const renderTabbar = require('../../utils/tabbar')
renderTabbar('mine')
    //获取axios工具函数
const axios = require('../../utils/request')
    // 设置服务器地址
axios.defaults.baseURL = 'http://fitness.h5.itsource.cn:3701'
    // 导入weui
require("weui"); //导入weui的css
let weui = require("weui.js"); //导入weui的js

// 从后端获取数据
axios.get("/api/user/info")
    .then(function(res) {
        console.log(res.data);

        let errno = res.data.errno;
        // 做判断,给用户一个提示
        if (errno == 0) {
            //成功

            let data = res.data.data

            let imgUrl = data.imgUrl; //头像
            let nickName = data.nickName; //用户名
            let sign = data.sign; //个性签名
            let circlesCount = data.circlesCount; //个性签名
            let duration = data.duration; //总运动时长
            let calorie = data.calorie; //卡路里


            document.querySelector("#imgUrl").src = axios.defaults.baseURL + imgUrl; //头像
            document.querySelector("#nickName").textContent = nickName; //用户名
            document.querySelector("#sign").textContent = sign; //个性签名
            document.querySelector("#circlesCount").textContent = circlesCount; //个性签名
            document.querySelector("#duration").textContent = duration; //总运动时长
            document.querySelector("#calorie").textContent = calorie; //卡路里
        } else if (errno === 10003) {
            //未登录
            weui.alert("请先登录", function() {
                location.href = "./login.html";
            });
        }
    });




//跳转到修改页面
document.querySelector("#userInfo").addEventListener("click", function() {
    location.href = "./edit.html";
});

//跳转到徽章页面
document.querySelector("#badge").addEventListener("click", function() {
    location.href = "./badges.html";
});

//跳转到运动页面
document.querySelector("#dataMotion").addEventListener("click", function() {
    location.href = "./data.html";
});